@extends('template.vo')
@section('content')
 <script language="javascript">
function CreateProvince() {

  var Primary =  $("#provinsi").val()

  if ((Primary == null) || (Primary == 0)) return;
  
  <?php 
  foreach($provinsi as $kota){ ?>
      if (Primary == {{$kota->provinsi_id}}) {

        var ProvState = new Array;
        ProvState[0] = new Option("Silahkan pilih");

        <?php
        $regional = DB::table('ref_regional')
                  ->where('regional_provinsi_id','=',$kota->provinsi_id)
                  ->get();
        $i=0;
        foreach($regional as $kota){?>
         ProvState[{{$i}}] = new Option("{{$kota->regional_name}}");
       <?php
       $i++;
        }
        ?>


      }
  <?php } ?>

  for (i=document.newforms.member_regional_name.options.length; i>0; i--) { 
  document.newforms.member_regional_name.options[i] = null;
  }

  for(i=0; i<ProvState.length; i++) {
  document.newforms.member_regional_name.options[i] = ProvState[i];
  }

  document.newforms.member_regional_name.options[0].selected = true;

}
</script>

<ol class="breadcrumb">
  <li class="active">Daftar agen</li>
</ol>

<div class="container-black">
 <label style="margin-top:10px"><u>Pencarian</u></label>
    <form action="{{URL::to('/virtualoffice/agens')}}" method="POST">


        <div class="row">
      <div class="col-md-9">
        <div class="col-md-1">
          <input name="filter" value="type" type="radio"  <?php if(Session::get('filter')=="type") echo "checked" ?> required></input>
        </div>
        <div class="col-lg-3">
        <label>Status</label>
        </div>
        <div class="col-lg-3">
           <select  class="form-control" name="typeby" style="height:30px" />
            <?php
              $type = array('all'=>'All','Aktif' => 'Aktif', 'Tidak aktif' => 'Tidak aktif');
              foreach ($type as $key => $val) {
                  if ($key == Session::get('list')) {
                      echo '<option value="' . $key . '" selected>' . $val . '</option>';
                  } else {
                      echo '<option value="' . $key . '">' . $val . '</option>';
                  }
              }
              ?>
          </select>
        </div>
      </div>
      </div>
      <br>


    


      <div class="row">
      <div class="col-md-9">
        <div class="col-md-1">
          <input name="filter" value="keyword" type="radio" <?php if(Session::get('filter')=="keyword") echo "checked" ?> ></input>
        </div>
        <div class="col-lg-3">
        <label>Kata kunci</label>
        </div>
        <div class="col-lg-3">
          <input type="text"  class="form-control" placeholder="Kata kunci" name="keyword" style="height:30px" value="{{Session::get('keyword')}}" /></input>
        </div>
        <div class="col-lg-3 col-md-offset-1">
          <select name="filterby" class="form-control" style="height:30px" />
            <?php
              $type = array('agencode' => 'Kode agen', 'agenname' => 'Nama agen');
              foreach ($type as $key => $val) {
                  if ($key == Session::get('filterby')) {
                      echo '<option value="' . $key . '" selected>' . $val . '</option>';
                  } else {
                      echo '<option value="' . $key . '">' . $val . '</option>';
                  }
              }
              ?>
          </select>
        </div>
      </div>
      </div>
      <br>
      <div class="row">
      <div class="col-md-9">
        <div class="col-md-3 col-md-offset-4">
             <button class="btn btn-sm btn-dark" type="submit" style="height:30px"><span class="fa fa-search"></span> Tampilkan</button>
        </div>
      </div>
      </div>
        

    </form>
  <label><u>Daftar agen</u></label>
    <br>

    <p><a data-toggle="modal" data-target="#tambah"><button class="btn btn-sm btn-dark" type="submit" style="height:30px" ><span class="fa fa-plus"></span> Tambah</button></a></p>
     <div class="table-responsive">
       <?php  
        $limit = 10;
        if(Input::get('page')==0 OR Input::get('page')==1){ 
         $no = 1;
        }
        else{
        $no = ((Input::get('page')-1)*$limit)+1;
        }
       ?>
     <table class="table table-bordered table-hover">
      <thead>
        <tr>
          <th>No</th>
          <th>Kode agen</th>
          <th>Nama agen</th>
          <th>Referal</th>
          <th>No telp / HP</th>
          <th>Tgl join</th>
          <th>Status</th>
          <th>Aksi</th>
        </tr>
      </thead>
      <tbody>
        <tr>
       
       @foreach($dataagen as $agen)
       <?php $refc = DB::table('sys_agen')
                  ->where('agen_id',$agen->agen_sponsor_id) 
                  ->count();
              $ref = DB::table('sys_agen')
                  ->where('agen_id',$agen->agen_sponsor_id) 
                  ->first();
              if($refc==0){
                $code = 'Perusahaan';
              }else{
                $code = $ref->agen_code;
              }

              $agenacc = DB::table('sys_account_agen')
                      ->where('account_agen_id',$agen->agen_id)
                      ->count();
                  ?>
         <td>{{$no}}</td>
         <td>{{$agen->agen_code}}</td>
         <td>{{$agen->member_name}}</td>
         <td>{{$code}}</td>
         <td>{{$agen->member_phone}}</td>
         <td>{{date("d-M-Y",strtotime($agen->member_joindate))}}</td>
         <td>{{$agen->member_status}}</td>

          <td style="width:50px"><a data-toggle="modal" data-target="#detail{{$agen->agen_id}}" title="Agen Detail"><button class="btn btn-xs btn-dark" ><span class="fa fa-file"></span> Detail</button></a></td>
        <?php $no++; ?>
      </tr>
      @endforeach
      </tbody>


    </table>
  <div class="text-right"><?php echo $dataagen->links(); ?></div>
  </div>
  </form>

     @foreach($dataagen as $agen)
                <div class="modal fade" id="detail{{$agen->agen_id}}" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false">
                <div class="modal-dialog modal-lg">
                  <div class="modal-content">
                    <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
 
                    <h4 align="center" class="modal-title"> <label style="margin-top:5px; margin-bottom:5px">Agen detail</label></h4>
                    </div>
                    <div align="left">
                              <div class="row" style="margin-top:10px">
                              <div class="col-md-10 col-md-offset-1">

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Tanggal join</label>
                                  </div>
                                  <div class="col-lg-5">
                                   <label>{{date("d-M-Y",strtotime($agen->member_joindate))}}</label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Referal agen (Kode)</label>
                                  </div>
                                  <div class="col-lg-5">
                                    <label><?php if($agen->agen_sponsor_id=="")echo "-"; else echo $agen->agen_sponsor_id; ?></label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Kode agen</label>
                                  </div>
                                  <div class="col-lg-5">
                                   <label>{{$agen->agen_code}}</label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Nama agen <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                   <label>{{$agen->member_name}}</label>                                  
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Alamat <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                   <label>{{$agen->member_address}}</label>
                                  </div>
                                  </div>
                                 
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Kota / Kabupaten <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <label>{{$agen->regional_name}}</label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Propinsi <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <label>{{$agen->provinsi_name}}</label>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Nomor telepon / HP<font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <label>{{$agen->member_phone}}</label>                
                                  </div>
                                  </div>

                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Alamat email<font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <label>{{$agen->member_email}}</label>
                                  </div>
                                  </div>
                              </div> 
                              </div>   
                    
                    </div>
                    <div class="modal-footer">

                    <button class="btn btn-sm btn-dark" style=" margin-right:5px" class="close" data-dismiss="modal"><span class="fa fa-times"></span> Batal</button></a>
                         
                    </div>
                  </div>
                </div>
              </div>
@endforeach



 <div class="modal fade" id="tambah" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false">
                <div class="modal-dialog modal-lg" style="width:55%">
                  <div class="modal-content">
                    <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
 
                    <h4 align="center" class="modal-title"> <label style="margin-top:5px; margin-bottom:5px">Tambah agen</label></h4>
                    </div>
                    <div align="left">
                              {{Form::open(array(
                                    'url' => '/virtualoffice/tambahagen/',
                                    'method' => 'POST',
                                     'name' => 'newforms'
                                  ))}}
                              <div class="row" style="margin-top:10px">
                              <div class="col-md-10 col-md-offset-1">
                                   <label>Data agen</label>
                                    <hr id="hr"> </hr>

                                        <div class="row">
                                        <div class="col-lg-6" style="margin-left:25px; margin-right:-25px">
                                        Nama agen <font color="red">*</font>
                                        </div>
                                        <div class="col-lg-6">
                                          <input type="text"  class="form-control" name="member_name" style="width:250px;height:30px"  required  /></input>
                                        </div>
                                        </div>
                                        <br>

                                        <div class="row">
                                        <div class="col-lg-6" style="margin-left:25px; margin-right:-25px">
                                        Alamat <font color="red">*</font>
                                        </div>
                                        <div class="col-lg-6">
                                          <textarea  class="form-control" name="member_address" style="width:250px;height:70px" required  /></textarea>
                                        </div>
                                        </div>
                                       
                                        <br>


                                        <div class="row">
                                        <div class="col-lg-6" style="margin-left:25px; margin-right:-25px">
                                        Propinsi <font color="red">*</font>
                                        </div>
                                        <div class="col-lg-6">
                                          <select  class="form-control" name="member_provinsi_id" id="provinsi" onChange="CreateProvince()" style="width:250px;height:30px" required />
                                          <option value="">Silahkan pilih</option>
                                          <?php 
                                          foreach($provinsi as $kota){
                                            if($kota->provinsi_id==$kota->provinsi_id){
                                              echo '<option value="'.$kota->provinsi_id.'" selected>'.$kota->provinsi_name.'</option>';
                                            }else{
                                              echo '<option value="'.$kota->provinsi_id.'">'.$kota->provinsi_name.'</option>';
                                            }
                                          }
                                          ?>
                                          </select>
                                        </div>
                                        </div>
                                        <br>


                                        <div class="row">
                                        <div class="col-lg-6" style="margin-left:25px; margin-right:-25px">
                                        Kota / Kabupaten <font color="red">*</font>
                                        </div>
                                        <div class="col-lg-6">
                                          <select  class="form-control" name="member_regional_name" style="width:250px;height:30px" required />
                                          <option value="">Silahkan pilih</option>
                                         
                                          </select>
                                        </div>
                                        </div>
                                        <br>

                                        <div class="row">
                                        <div class="col-lg-6" style="margin-left:25px; margin-right:-25px">
                                        Nomor telepon / HP<font color="red">*</font>
                                        </div>
                                        <div class="col-lg-6">
                                          <input type="phone"  class="form-control" name="member_phone" style="width:250px;height:30px"  required /></input>
                                        </div>
                                        </div>

                                        <br>

                                        <div class="row">
                                        <div class="col-lg-6" style="margin-left:25px; margin-right:-25px">
                                        Alamat email<font color="red">*</font>
                                        </div>
                                        <div class="col-lg-6">
                                          <input type="email"  class="form-control" name="member_email" style="width:250px;height:30px"  required /></input>
                                        </div>
                                        </div>
                                        <br>

                                        <hr id="hr"> </hr>
                                        <input type="checkbox" name="tos" value="1" required></input>  Saya setuju dengan <font color="blue"><u>syarat dan ketentuan</u></font><span class="pull-right"><font color="red">* Data tidak boleh kosong</font></span>
                                        <br>
                                        <br>

                                      

                              </div> 
                              </div>   
                    
                    </div>
                    <div class="modal-footer">

                    <button class="btn btn-sm btn-dark" style=" margin-right:5px" type="submit"><span class="fa  fa-floppy-o"></span> Simpan</button>{{Form::close()}}}
                         
                    </div>
                  </div>
                </div>
              </div>
</div>


@stop
@stop